package com.download.backstage.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.download.web.entity.SysNavBar;
import com.download.web.service.ISysNavBarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @description: 导航类型管理
 * @author: cmy
 * @create: 2019-02-23 16:33
 **/
@RestController
@RequestMapping("/backstage/nav")
public class BackstageNavController {

    @Autowired
    private ISysNavBarService sysNavBarService;
    /**
     * 按父级id查找子级菜单
     * @param parentId
     * @return
     */
    @RequestMapping("/navBarListByParent")
    public List<SysNavBar> navBarListByParent(Integer parentId){
        if (null==parentId) parentId=0;
        List<SysNavBar> navBarList=sysNavBarService.list(new QueryWrapper<SysNavBar>().eq("parent_id",parentId));
        return navBarList;
    }

    /**
     * 文章类型查询
     * @return
     */
    @RequestMapping("/articleTypeList")
    public List<SysNavBar> navBarListByParent(){
        List<SysNavBar> navBarList=sysNavBarService.list(new QueryWrapper<SysNavBar>().ne("parent_id",0));
        return navBarList;
    }

    /**
     * 新增导航栏菜单
     * @param sysNavBar
     */
    @RequestMapping("/addNav")
    public Integer addNav(@RequestBody SysNavBar sysNavBar){
        sysNavBarService.save(sysNavBar);
        return sysNavBar.getId();
    }

    @RequestMapping("/updateNavName")
    public void updateNavName(@RequestBody SysNavBar sysNavBar){
        sysNavBarService.updateNameById(sysNavBar.getName(),sysNavBar.getId());
    }

    /**
     * 按id删除导航栏菜单
     * @param id
     */
    @RequestMapping("/delNavById")
    public void delNavById(Integer id){
        sysNavBarService.removeById(id);
        sysNavBarService.remove(new QueryWrapper<SysNavBar>().eq("parent_id",id));
    }

}
